package com.ndp.fb.walle.business.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ndp.fb.rdb.api.DictionaryRdbService;
import com.ndp.fb.rdb.api.VersionInfoRdbService;
import com.ndp.fb.rdb.model.Dictionary;
import com.ndp.fb.rdb.model.version.VersionInfo;
import com.ndp.fb.walle.business.VersionInfoService;
import org.springframework.stereotype.Component;
import java.util.List;

/**
 * Created by elvisxiong on 16/2/29.
 */
@Component
public class VersionInfoServiceImpl implements VersionInfoService {

    @Reference
    VersionInfoRdbService versionInfoRdbService;

    @Reference
    DictionaryRdbService dictionaryRdbService;

    @Override
    public List<VersionInfo> getVersionInfo(long dictionaryId) {
        return versionInfoRdbService.getVersionInfoList(dictionaryId);
    }

    @Override
    public Long save(VersionInfo versionInfo) {
        return versionInfoRdbService.save(versionInfo);
    }

    @Override
    public void delete(Long id) {
        versionInfoRdbService.delete(id);
    }

    @Override
    public String getCurrentVersionInfo() {
        return versionInfoRdbService.getCurrentVersionInfo();
    }


    @Override
    public List<VersionInfo> getVersionInfo(String languageCode) {
        Dictionary dictionary = dictionaryRdbService.getDictionaryByCode(languageCode);
        if(dictionary != null){
            Long id = dictionary.getId();
           return  versionInfoRdbService.getVersionInfoList(id);
        }
        return null;
    }
}
